package com.ruoyi.business.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.business.vo.TNoticeInfoVo;
import com.ruoyi.business.service.ITNoticeInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 通知公告Controller
 *
 * @author Tellsea
 * @date 2024-01-17
 */
@Api(tags = "通知公告Controller")
@RestController
@RequestMapping("/business/noticeInfo")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class TNoticeInfoController extends BaseController {

    private final ITNoticeInfoService tNoticeInfoService;

    @ApiOperation("查询通知公告列表")
//    @PreAuthorize("@ss.hasPermi('business:noticeInfo:list')")
    @GetMapping("/list")
    public TableDataInfo<TNoticeInfoVo> list(TNoticeInfoVo entity) {
        return tNoticeInfoService.queryList(entity);
    }

    @ApiOperation("查询通知公告所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(TNoticeInfoVo entity) {
        return AjaxResult.success("查询成功", tNoticeInfoService.queryAll(entity));
    }

    @ApiOperation("导出通知公告列表")
    @PreAuthorize("@ss.hasPermi('business:noticeInfo:export')")
    @Log(title = "通知公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TNoticeInfoVo entity) {
        List<TNoticeInfoVo> list = tNoticeInfoService.queryAll(entity);
        ExcelUtil<TNoticeInfoVo> util = new ExcelUtil<>(TNoticeInfoVo.class);
        util.exportExcel(response, list, "通知公告数据");
    }

    @ApiOperation("获取通知公告详细信息")
//    @PreAuthorize("@ss.hasPermi('business:noticeInfo:query')")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", tNoticeInfoService.queryById(id));
    }

    @ApiOperation("新增通知公告")
    @PreAuthorize("@ss.hasPermi('business:noticeInfo:add')")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody TNoticeInfoVo entity) {
        return toAjax(tNoticeInfoService.save(entity));
    }

    @ApiOperation("修改通知公告")
    @PreAuthorize("@ss.hasPermi('business:noticeInfo:edit')")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody TNoticeInfoVo entity) {
        return toAjax(tNoticeInfoService.updateById(entity));
    }

    @ApiOperation("删除通知公告")
    @PreAuthorize("@ss.hasPermi('business:noticeInfo:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tNoticeInfoService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
